package com.ems.service.impl;

import com.ems.entity.TProductLine;
import com.ems.mapper.TProductLineMapper;
import com.ems.service.ITProductLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZZH
 * @since 2022-06-27
 */
@Service
public class TProductLineServiceImpl extends ServiceImpl<TProductLineMapper, TProductLine> implements ITProductLineService {

    @Override
    public boolean bindMachine(TProductLine tProductLine) {
        baseMapper.bindMachine(tProductLine);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean unbindMachine(TProductLine tProductLine) {
        baseMapper.unbindMachine(tProductLine);
        if(tProductLine.getMacId() != null){
            baseMapper.updateMachine(tProductLine.getMacId());
        }
        else{return false;}
        return true;
    }

    @Override
    public boolean updateProcess(TProductLine tProductLine) {
        baseMapper.updateProcess(tProductLine);
        return true;
    }

    @Override
    public boolean bindEmployee(TProductLine tProductLine) {
        baseMapper.bindEmployee(tProductLine);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<TProductLine> check(Integer id) {
        int pid = baseMapper.permit(id);
        if(pid == 1){
            List<TProductLine> tProductLines = baseMapper.check();
            return tProductLines;
        }else{
            return null;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean unbindEmployee(TProductLine tProductLine) {
        baseMapper.unbindEmployee(tProductLine);
        if (tProductLine.getOperationOneId()!=null||tProductLine.getOperationTwoId()!=null||tProductLine.getOperationThreeId()!=null){
            if (tProductLine.getOperationOneId()!=null){
                baseMapper.updateEmp(tProductLine.getOperationOneId());
            }
            if (tProductLine.getOperationTwoId()!=null){
                baseMapper.updateEmp(tProductLine.getOperationTwoId());
            }
            if (tProductLine.getOperationThreeId()!=null){
                baseMapper.updateEmp(tProductLine.getOperationThreeId());
            }
        }else {
            return false;
        }
//        List<TProductLine> list=baseMapper.selectOperation(tProductLine);
//        System.out.println(list.get(0)+"==========================");
//        baseMapper.updateEmp();
        return true;
    }
}
